﻿using System;
using System.Reflection;
using Common.Reflection.Model;
using System.Collections.Generic;
namespace Common.Reflection.DAL
{
    public class Entity
    {
        /// <summary>
        /// 获取必填错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetRequireMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Require), true);
            if (objs.Length > 0)
            {

                if (string.IsNullOrEmpty(Convert.ToString(proper.GetValue(obj, null))))
                {
                    Reflection.Model.Attribute.Require require = objs[0] as Reflection.Model.Attribute.Require;
                    message = require.Message;
                }
            }
            return message;
        }

        /// <summary>
        /// 获取最大值错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMaxValueMessage(PropertyInfo proper, object obj, bool hasValue)
        {

            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.MaxValue), true);

            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        string value = Convert.ToString(proper.GetValue(obj, null));
                        Reflection.Model.Attribute.MaxValue require = objs[0] as Reflection.Model.Attribute.MaxValue;
                        if (hasValue)
                        {
                            if (Convert.ToInt32(value) > require.TheValue)
                            {
                                message = require.Message;
                            }
                        }
                        else
                        {
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    string value = Convert.ToString(proper.GetValue(obj, null));
                    Reflection.Model.Attribute.MaxValue require = objs[0] as Reflection.Model.Attribute.MaxValue;
                    if (hasValue)
                    {
                        if (Convert.ToInt32(value) > require.TheValue)
                        {
                            message = require.Message;
                        }
                    }
                    else
                    {
                        message = require.Message;
                    }
                }
            }

            return message;
        }
        /// <summary>
        /// 判断是否一个新的未初始化的对象
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool isInited(object obj)
        {
            Type type = obj.GetType();
            PropertyInfo[] myPropertyInfo = type.GetProperties();
            bool inited = true;
            for (int i = 0; i < myPropertyInfo.Length; i++)
            {
                string value = Convert.ToString(myPropertyInfo[i].GetValue(obj, null));
                if (myPropertyInfo[i].GetValue(obj, null) != null && myPropertyInfo[i].GetValue(obj, null).ToString() != "0001-1-1 0:00:00" && myPropertyInfo[i].GetValue(obj, null).ToString() != "")
                {
                    inited = false;
                    break;
                }
            }
            return inited;
        }


        /// <summary>
        /// 获取最小值错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMinValueMessage(PropertyInfo proper, object obj, bool hasValue)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.MinValue), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        string value = Convert.ToString(proper.GetValue(obj, null));

                        Reflection.Model.Attribute.MinValue require = objs[0] as Reflection.Model.Attribute.MinValue;
                        if (hasValue)
                        {
                            if (Convert.ToInt32(value) < require.TheValue)
                            {
                                message = require.Message;
                            }
                        }
                        else
                        {
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    string value = Convert.ToString(proper.GetValue(obj, null));

                    Reflection.Model.Attribute.MinValue require = objs[0] as Reflection.Model.Attribute.MinValue;
                    if (hasValue)
                    {
                        if (Convert.ToInt32(value) < require.TheValue)
                        {
                            message = require.Message;
                        }
                    }
                    else
                    {
                        message = require.Message;
                    }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取字符串或数字最大长度错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMaxLengthMessage(PropertyInfo proper, object obj, bool hasValue)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.MaxLength), true);

            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        string value = Convert.ToString(proper.GetValue(obj, null));
                        Reflection.Model.Attribute.MaxLength require = objs[0] as Reflection.Model.Attribute.MaxLength;

                        if (hasValue)
                        {
                            if (Convert.ToInt32(value.ToString().Length) > require.TheLength)
                            {
                                message = require.Message;
                            }
                        }
                        else
                        {
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    string value = Convert.ToString(proper.GetValue(obj, null));
                    Reflection.Model.Attribute.MaxLength require = objs[0] as Reflection.Model.Attribute.MaxLength;

                    if (hasValue)
                    {
                        if (Convert.ToInt32(value.ToString().Length) > require.TheLength)
                        {
                            message = require.Message;
                        }
                    }
                    else
                    {
                        message = require.Message;
                    }
                }

            }
            return message;
        }

        /// <summary>
        /// 获取字符串或数字最大长度错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMinLengthMessage(PropertyInfo proper, object obj, bool hasValue)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.MinLength), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        string value = Convert.ToString(proper.GetValue(obj, null));

                        Reflection.Model.Attribute.MinLength require = objs[0] as Reflection.Model.Attribute.MinLength;
                        if (hasValue)
                        {
                            if (Convert.ToInt32(value.ToString().Length) < require.TheLength)
                            {
                                message = require.Message;
                            }
                        }
                        else
                        {
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    string value = Convert.ToString(proper.GetValue(obj, null));

                    Reflection.Model.Attribute.MinLength require = objs[0] as Reflection.Model.Attribute.MinLength;
                    if (hasValue)
                    {
                        if (Convert.ToInt32(value.ToString().Length) < require.TheLength)
                        {
                            message = require.Message;
                        }
                    }
                    else
                    {
                        message = require.Message;
                    }
                }

            }
            return message;
        }

        /// <summary>
        /// 获取邮箱拼写错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetEmailMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Email), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsEmail())
                        {
                            Reflection.Model.Attribute.Email require = objs[0] as Reflection.Model.Attribute.Email;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //    if (!Common.StringValidate.IsEmail(Convert.ToString(proper.GetValue(obj, null))))
                    //    {
                    Reflection.Model.Attribute.Email require = objs[0] as Reflection.Model.Attribute.Email;
                    message = require.Message;
                    //    }
                }
            }
            return message;
        }
        /// <summary>
        /// 获取时间拼写错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetTimeMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Time), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsTime())
                        {
                            Reflection.Model.Attribute.Time require = objs[0] as Reflection.Model.Attribute.Time;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsTime(Convert.ToString(proper.GetValue(obj, null))))
                    //    {
                    Reflection.Model.Attribute.Time require = objs[0] as Reflection.Model.Attribute.Time;
                    message = require.Message;
                    //    }
                }
            }
            return message;
        }
        /// <summary>
        /// 获取邮编拼写错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetZipCodeMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.ZipCode), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsZipCode())
                        {
                            Reflection.Model.Attribute.ZipCode require = objs[0] as Reflection.Model.Attribute.ZipCode;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsZipCode(Convert.ToString(proper.GetValue(obj, null))))
                    //   {
                    Reflection.Model.Attribute.ZipCode require = objs[0] as Reflection.Model.Attribute.ZipCode;
                    message = require.Message;
                    //   }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取数字填写错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetNumberMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Number), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsNumber())
                        {
                            Reflection.Model.Attribute.Number require = objs[0] as Reflection.Model.Attribute.Number;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsNumber(Convert.ToString(proper.GetValue(obj, null))))
                    //   {
                    Reflection.Model.Attribute.Number require = objs[0] as Reflection.Model.Attribute.Number;
                    message = require.Message;
                    //    }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取浮点数输入错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetDecimalMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Decimal), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsDecimal())
                        {
                            Reflection.Model.Attribute.Decimal require = objs[0] as Reflection.Model.Attribute.Decimal;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //    Common.LogManager.GetInstance().Log("空对象");
                    //    if (!Common.StringValidate.IsDecimal(Convert.ToString(proper.GetValue(obj, null))))
                    //    {
                    Reflection.Model.Attribute.Decimal require = objs[0] as Reflection.Model.Attribute.Decimal;
                    message = require.Message;
                    //     }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取小数输入错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetDoubleMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Double), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsDouble())
                        {
                            Reflection.Model.Attribute.Double require = objs[0] as Reflection.Model.Attribute.Double;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsDouble(Convert.ToString(proper.GetValue(obj, null))))
                    //   {
                    Reflection.Model.Attribute.Double require = objs[0] as Reflection.Model.Attribute.Double;
                    message = require.Message;
                    //  }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取邮编填写错误信息
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetUrlMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Url), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsUrl())
                        {
                            Reflection.Model.Attribute.Url require = objs[0] as Reflection.Model.Attribute.Url;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsUrl(Convert.ToString(proper.GetValue(obj, null))))
                    //   {
                    Reflection.Model.Attribute.Url require = objs[0] as Reflection.Model.Attribute.Url;
                    message = require.Message;
                    //  }
                }
            }
            return message;
        }
        /// <summary>
        /// 判断字段是否需要被除以100
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static bool IsDivideByHundred(PropertyInfo proper)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.DividedByHundred), true);
            if (objs.Length > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 判断字段是否是金额
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static bool IsMoney(PropertyInfo proper)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Money), true);
            if (objs.Length > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 获取日期填写错误信息(支持闰年) 格式yyyy-MM-dd 或 yyyy/MM/dd
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetDateMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Date), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsDate())
                        {
                            Reflection.Model.Attribute.Date require = objs[0] as Reflection.Model.Attribute.Date;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //  if (!Common.StringValidate.IsDate(Convert.ToString(proper.GetValue(obj, null))))
                    //  {
                    Reflection.Model.Attribute.Date require = objs[0] as Reflection.Model.Attribute.Date;
                    message = require.Message;
                    //   }
                }
            }
            return message;
        }
        /// <summary>
        /// 获取日期填写错误信息(支持闰年) 格式yyyy-MM-dd 或 yyyy/MM/dd
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMobileMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Mobile), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsMobile())
                        {
                            Reflection.Model.Attribute.Mobile require = objs[0] as Reflection.Model.Attribute.Mobile;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //   if (!Common.StringValidate.IsMobile(Convert.ToString(proper.GetValue(obj, null))))
                    //   {
                    Reflection.Model.Attribute.Mobile require = objs[0] as Reflection.Model.Attribute.Mobile;
                    message = require.Message;
                    //   }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取日期填写错误信息(支持闰年) 格式yyyy-MM-dd 或 yyyy/MM/dd
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetIDCardMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.IDCard), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsIDCard())
                        {
                            Reflection.Model.Attribute.IDCard require = objs[0] as Reflection.Model.Attribute.IDCard;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //  if (!Common.StringValidate.IsIDCard(Convert.ToString(proper.GetValue(obj, null))))
                    //  {
                    Reflection.Model.Attribute.IDCard require = objs[0] as Reflection.Model.Attribute.IDCard;
                    message = require.Message;
                    //   }
                }
            }
            return message;
        }

        /// <summary>
        /// 获取日期填写错误信息(支持闰年) 格式yyyy-MM-dd 或 yyyy/MM/dd
        /// </summary>
        /// <param name="proper"></param>
        /// <returns></returns>
        internal static string GetMoneyMessage(PropertyInfo proper, object obj)
        {
            string message = string.Empty;
            Object[] objs = proper.GetCustomAttributes(typeof(Reflection.Model.Attribute.Money), true);
            if (objs.Length > 0)
            {
                if (!isInited(obj))
                {
                    if (proper.GetValue(obj, null) != null)
                    {
                        if (!Convert.ToString(proper.GetValue(obj, null)).IsMoney())
                        {
                            Reflection.Model.Attribute.Money require = objs[0] as Reflection.Model.Attribute.Money;
                            message = require.Message;
                        }
                    }
                }
                else
                {
                    //  if (!Common.StringValidate.IsIDCard(Convert.ToString(proper.GetValue(obj, null))))
                    //  {
                    Reflection.Model.Attribute.Money require = objs[0] as Reflection.Model.Attribute.Money;
                    message = require.Message;
                    //   }
                }
            }
            return message;
        }
        /// <summary>
        /// 验证对象是否满足类定义时的条件
        /// </summary>
        /// <returns></returns>
        public static List<ErrorMessages> Validate(object obj)
        {
            List<ErrorMessages> messages = new List<ErrorMessages>();
            Type type = obj.GetType();
            PropertyInfo[] myPropertyInfo = type.GetProperties();

            foreach (PropertyInfo p in myPropertyInfo)
            {
                string colname = p.Name;
                string requireMessage = GetRequireMessage(p, obj);
                string emailMessage = GetEmailMessage(p, obj);
                string numberMessage = GetNumberMessage(p, obj);
                string maxValueMessage = GetMaxValueMessage(p, obj, true);
                string minValueMessage = GetMinValueMessage(p, obj, true);
                string decimalMessage = GetDecimalMessage(p, obj);
                string maxLengthMessage = GetMaxLengthMessage(p, obj, true);
                string minLengthMessage = GetMinLengthMessage(p, obj, true);
                string urlmessage = GetUrlMessage(p, obj);
                string zipcodemessage = GetZipCodeMessage(p, obj);
                string doublemessage = GetDoubleMessage(p, obj);
                string timemessage = GetTimeMessage(p, obj);
                string datemessage = GetDateMessage(p, obj);
                string mobilemessage = GetMobileMessage(p, obj);
                string idcardmessage = GetIDCardMessage(p, obj);

                if (!string.IsNullOrEmpty(requireMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, requireMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(emailMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, emailMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(maxValueMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, maxValueMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(minValueMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, minValueMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(numberMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, numberMessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(decimalMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, decimalMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(maxLengthMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, maxLengthMessage);
                    messages.Add(message);
                }

                if (!string.IsNullOrEmpty(minLengthMessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, minLengthMessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(urlmessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, urlmessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(zipcodemessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, zipcodemessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(doublemessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, doublemessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(timemessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, timemessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(datemessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, datemessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(mobilemessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, mobilemessage);
                    messages.Add(message);
                }
                if (!string.IsNullOrEmpty(idcardmessage))
                {
                    ErrorMessages message = new ErrorMessages(colname, idcardmessage);
                    messages.Add(message);
                }

            }
            return messages;
        }
        /// <summary>
        /// 验证对象是否满足类定义时的条件
        /// </summary>
        /// <returns></returns>
        public static bool ValidatePassed(object obj)
        {
            List<ErrorMessages> messages = Validate(obj);
            for (int i = 0; i < messages.Count; i++)
            {
                messages[i].Message.ToString().Debug();
            }
            if (messages.Count == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 从页面Form表单接收数据
        /// </summary>
        /// <returns></returns>
        public static object CollectDataFromForm(object obj)
        {
            Type type = obj.GetType();
            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo p in properties)
            {
                string columnName = p.Name;
                string PType = p.PropertyType.ToString();
                Reflection.DAL.Managers.DBHelper.Operator(p, PType, System.Web.HttpContext.Current.Request.Form[columnName], obj, 1);
            }

            return obj;
        }
    }
}
